//
//  ViewController.swift
//  DouyuTV
//
//  Created by apple on 2017/7/1.
//  Copyright © 2017年 apple. All rights reserved.
//

import UIKit
import SnapKit
import Alamofire
import SDCycleScrollView

class ViewController: UIViewController,JTSegmentControlDelegate,SDCycleScrollViewDelegate {
 
  let headerview = UIView ()
    var cycleScrollView = SDCycleScrollView()
    
    override func viewWillAppear(_ animated: Bool) {
        
        self.navigationController?.isNavigationBarHidden = true
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
       self.createHeaderView()
        
        self.createSlider()
        
        
        self.createSDcycleView()

}
    
    func createSDcycleView () {
    
    let  remoteImages = NSArray(objects: "http://img1.mm131.com/pic/1997/14.jpg", "http://img1.mm131.com/pic/1997/15.jpg", "http://img1.mm131.com/pic/1997/18.jpg", "http://img1.mm131.com/pic/1997/19.jpg")
     let   height = (KscreenHeight * 0.1);
    cycleScrollView.frame = CGRect.init(x: 0, y: height+44, width: KscreenWidth, height: KscreenHeight * 0.2)
        
     cycleScrollView.imageURLStringsGroup = remoteImages as! [Any]
    
        cycleScrollView.autoScrollTimeInterval = 1.5
        
        cycleScrollView.currentPageDotColor = UIColor.orange
        cycleScrollView.delegate = self
        
        self.view .addSubview(cycleScrollView)
    }
    func createHeaderView(){
        
        headerview.frame = CGRect.init(x: 0, y: 0, width: KscreenWidth, height: KscreenHeight * 0.1)
        
        headerview.backgroundColor = UIColor.orange
        
        self.view .addSubview(headerview)
        
        let image = UIImageView ()
        image.backgroundColor = UIColor.red
        image.tag = 50
        image.isUserInteractionEnabled = true
        image.image = UIImage.init(named: "home_mobilegameSuspendedView_appicontest_60x60_")!
       
        headerview .addSubview(image)
        
        image.snp.makeConstraints { (make)->Void in
            
            make.left.equalTo(self.view).offset(10)
            make.top.equalTo(self.view).offset(25)
            make.width.equalTo(40)
            make.height.equalTo(30)
            
            
            
            
        }
        let setting = UIImageView()
        
        setting.image = UIImage.init(named: "setting")!
        
        setting.tag = 100
        
        setting.isUserInteractionEnabled = true
        
        headerview .addSubview(setting)
        
        setting.snp.makeConstraints { (make)->Void in
            
           make.trailing.equalTo(self.view).offset(-10)
            
           make.top.equalTo(self.view).offset(30)
            
           make.width.height.equalTo(20)
            
            
        }
        let playgame = UIImageView()
        
        playgame.image = UIImage.init(named: "home_newGameicon_24x24_")
        
        playgame.tag = 200
        
        playgame.isUserInteractionEnabled = true
        
        headerview .addSubview(playgame)
        
        
        playgame.snp.makeConstraints { (make)->Void in
            
            make.trailing.equalTo(setting).offset(-35)
            make.top.equalTo(setting)
        
            make.width.height.equalTo(setting)
            
        }
        
        let tap  = UITapGestureRecognizer.init(target: self, action: #selector(imageClick(_:)))
        
        image .addGestureRecognizer(tap)
        
        setting.addGestureRecognizer(tap)
        
        playgame.addGestureRecognizer(tap)
        
    }
    
    func imageClick (_ tag:Int) {
        
        switch tag  {
        case 50:
            print(tag)
            break;
            
        case 100:
            
            print(tag)
            break;
            
        case 200:
            
            print(tag)
            break;
        default:
            break;
        }
        
        
    }
    
    func  createSlider(){
        
        let   height = KscreenHeight * 0.1
        
        let  frame = CGRect(x: 0, y: height, width: KscreenWidth, height: 44.0)
        
        let segmentControl = JTSegmentControl(frame: frame)
        segmentControl.backgroundColor = UIColor.clear
        segmentControl.delegate = self
        segmentControl.itemSelectedBackgroundColor = UIColor.clear
        segmentControl.items = ["推荐", "手游", "娱乐", "游戏", "趣玩"]
        segmentControl.autoScrollWhenIndexChange = true
        view.addSubview(segmentControl)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    
    }
    //点击活动快方法
    
    func didSelected(segement: JTSegmentControl, index: Int) {
        
        
        print(index)
    }
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int) {
        
        switch index {
        case 0:
            print(index)
            break;
            
        case 1:
            print(index)
            break;
        case 2:
            print(index)
            break;
            
            case 3:
            print(index)
            break;
        default:
            break;
        }
        
    }

}

